package com.theory.gateway.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * 用下面的方法可以代替配置文件
 */
@Configuration
public class RouteConfig {

    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        RouteLocatorBuilder.Builder routes = builder.routes();
        routes.route("service-core", r -> r.path("/core/**").uri("lb://service-core"));
        routes.route("service-sms", r -> r.path("/sms/**").uri("lb://service-sms"));
        routes.route("service-oss", r -> r.path("/oss/**").uri("lb://service-oss"));

        return routes.build();
    }
}
